package com.xbongbong.pro.bi.commons.pojo;

import com.xbongbong.paas.enums.AggTypeEnum;
import com.xbongbong.pro.domain.entity.ChartEntity;
import com.xbongbong.pro.statistic.result.pojo.FieldAttrPojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

/**
 * 提供组装子查询SQL需要的相关参数
 *
 * @author zyy
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SubSqlParamPojo {

    /**
     * 图表实体
     */
    private ChartEntity chartEntity;

    /**
     * 拆解后的计算公式数组
     */
    private List<String> fieldsList;

    /**
     * 计算字段实体
     */
    private FieldAttrPojo fieldAttrPojo;

    /**
     * 汇总字段sql数组
     */
    private List<String> aggFieldsList;

    /**
     * 汇总字段sql数组（统计表总计、小计使用）
     */
    private List<String> sumTotalFieldsList;

    /**
     * 子查询外层sql数组
     */
    private List<String> subQuerySqlOfCountList;

    /**
     * count、count_distinct公式 ->  对应的SQL
     */
    private Map<String, String> sql4FormulaByCountMap;

    /**
     * 非count、count_distinct公式 -> 对应的SQL
     */
    private Map<String, String> sql4FormulaMap;

    /**
     * sql字段对应的别名
     */
    private Map<String, String> innerSqlAlisaMap;

    /**
     * 第一层函数的大写英文
     */
    private String firstFormulaName;
    /**
     * 公式对应的汇总类型
     */
    private AggTypeEnum aggType;


    public static SubSqlParamPojo init(ChartEntity chartEntity, List<String> fieldsList,FieldAttrPojo fieldAttrPojo, List<String> aggFieldsList,
                                       List<String> sumTotalFieldsList, List<String> subQuerySqlOfCountList,
                                       Map<String, String> sql4FormulaByCountMap,Map<String, String> sql4FormulaMap,
                                       Map<String, String> innerSqlAlisaMap,String firstFormulaName,AggTypeEnum aggType) {
        SubSqlParamPojo subSqlParamPojo = new SubSqlParamPojo();
        subSqlParamPojo.setChartEntity(chartEntity);
        subSqlParamPojo.setFieldsList(fieldsList);
        subSqlParamPojo.setFieldAttrPojo(fieldAttrPojo);
        subSqlParamPojo.setAggFieldsList(aggFieldsList);
        subSqlParamPojo.setSumTotalFieldsList(sumTotalFieldsList);
        subSqlParamPojo.setSubQuerySqlOfCountList(subQuerySqlOfCountList);
        subSqlParamPojo.setSql4FormulaByCountMap(sql4FormulaByCountMap);
        subSqlParamPojo.setSql4FormulaMap(sql4FormulaMap);
        subSqlParamPojo.setInnerSqlAlisaMap(innerSqlAlisaMap);
        subSqlParamPojo.setFirstFormulaName(firstFormulaName);
        subSqlParamPojo.setAggType(aggType);
        return subSqlParamPojo;
    }
}
